package com.pen.interfece.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pen.interfece.mapper.DormitoryMapper;
import com.pen.interfece.pojo.PageResult;
import com.pen.interfece.pojo.dto.DormitoryPageQueryDTO;
import com.pen.interfece.pojo.entity.Admin;
import com.pen.interfece.pojo.entity.Dormitory;
import com.pen.interfece.pojo.vo.StudentVO;
import com.pen.interfece.service.DormitorySerivice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DormitoryServiceImpl implements DormitorySerivice {
    @Autowired
    private DormitoryMapper dormitoryMapper;
    @Override
    public void save(Dormitory dormitory) {
        dormitoryMapper.save(dormitory);

    }

    @Override
    public void deleteBatch(List<Long> ids) {
        for (Long id : ids) {
            dormitoryMapper.deleteById(id);
        }
    }

    @Override
    public void update(Dormitory dormitory) {
        dormitoryMapper.update(dormitory);
    }

    @Override
    public PageResult pageQuery(DormitoryPageQueryDTO dormitoryPageQueryDTO) {
        //开始分页查询，插件执行
        PageHelper.startPage(dormitoryPageQueryDTO.getPage(),dormitoryPageQueryDTO.getPageSize());
        Page<Dormitory> page=dormitoryMapper.pageQuery(dormitoryPageQueryDTO);
        long total = page.getTotal();
        List<Dormitory> records = page.getResult();


        return new PageResult(total,records);
    }

    @Override
    public List<StudentVO> selectByDormitoryId(int id) {
       List<StudentVO> list= dormitoryMapper.selectByDormitoryId(id);
       return list;
    }
}
